<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
<script>
    (function(){
        if(''){
            if (prompt('请输入文章密码') !== ''){
                alert('密码错误！');
                history.back();
            }
        }
    })();
</script>
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-flash.min.css">
  <script src="/lib/pace/pace.min.js"></script>


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('https://kechenhh.gitee.io').hostname,
    root: '/',
    scheme: 'Gemini',
    version: '7.7.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
    copycode: {"enable":false,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
  };
</script>

  <meta name="description" content="官方文档https:&#x2F;&#x2F;cli.vuejs.org&#x2F;zh&#x2F; 参考https:&#x2F;&#x2F;www.jianshu.com&#x2F;p&#x2F;fc94ad12cb9a https:&#x2F;&#x2F;www.chensheng.group&#x2F;2019&#x2F;12&#x2F;18&#x2F;113-vue-cli4.0%E5%AD%A6%E4%B9%A0&#x2F; 前提条件安装node.js下载地址：https:&#x2F;&#x2F;nodejs.org&#x2F;en&#x2F;download&#x2F; (npm会在">
<meta property="og:type" content="article">
<meta property="og:title" content="vue-cli(脚手架)创建Vue项目">
<meta property="og:url" content="https://kechenhh.gitee.io/vue-cli(%E8%84%9A%E6%89%8B%E6%9E%B6)%E5%88%9B%E5%BB%BAVue%E9%A1%B9%E7%9B%AE.html">
<meta property="og:site_name" content="我的博客">
<meta property="og:description" content="官方文档https:&#x2F;&#x2F;cli.vuejs.org&#x2F;zh&#x2F; 参考https:&#x2F;&#x2F;www.jianshu.com&#x2F;p&#x2F;fc94ad12cb9a https:&#x2F;&#x2F;www.chensheng.group&#x2F;2019&#x2F;12&#x2F;18&#x2F;113-vue-cli4.0%E5%AD%A6%E4%B9%A0&#x2F; 前提条件安装node.js下载地址：https:&#x2F;&#x2F;nodejs.org&#x2F;en&#x2F;download&#x2F; (npm会在">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/kechenhh/tmp/raw/master/img/20201103110637.png">
<meta property="og:image" content="https://gitee.com/kechenhh/tmp/raw/master/img/20201103110915.png">
<meta property="og:image" content="https://gitee.com/kechenhh/tmp/raw/master/img/20201103133004.png">
<meta property="og:image" content="https://gitee.com/kechenhh/tmp/raw/master/img/20201103134157.png">
<meta property="article:published_time" content="2020-11-03T08:30:15.000Z">
<meta property="article:modified_time" content="2021-06-06T07:34:03.878Z">
<meta property="article:author" content="kechenhh">
<meta property="article:tag" content="Vue">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/kechenhh/tmp/raw/master/img/20201103110637.png">

<link rel="canonical" href="https://kechenhh.gitee.io/vue-cli(%E8%84%9A%E6%89%8B%E6%9E%B6)%E5%88%9B%E5%BB%BAVue%E9%A1%B9%E7%9B%AE.html">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>vue-cli(脚手架)创建Vue项目 | 我的博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">我的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle"> my blog</p>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="none"
           placeholder="搜索..." spellcheck="false"
           type="text" id="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://kechenhh.gitee.io/vue-cli(%E8%84%9A%E6%89%8B%E6%9E%B6)%E5%88%9B%E5%BB%BAVue%E9%A1%B9%E7%9B%AE.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="kechenhh">
      <meta itemprop="description" content="学习笔记">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          vue-cli(脚手架)创建Vue项目
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-11-03 16:30:15" itemprop="dateCreated datePublished" datetime="2020-11-03T16:30:15+08:00">2020-11-03</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-06-06 15:34:03" itemprop="dateModified" datetime="2021-06-06T15:34:03+08:00">2021-06-06</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Vue/" itemprop="url" rel="index">
                    <span itemprop="name">Vue</span>
                  </a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="官方文档"><a href="#官方文档" class="headerlink" title="官方文档"></a>官方文档</h2><p><a href="https://cli.vuejs.org/zh/" target="_blank" rel="noopener">https://cli.vuejs.org/zh/</a></p>
<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><p><a href="https://www.jianshu.com/p/fc94ad12cb9a" target="_blank" rel="noopener">https://www.jianshu.com/p/fc94ad12cb9a</a></p>
<p><a href="https://www.chensheng.group/2019/12/18/113-vue-cli4.0%E5%AD%A6%E4%B9%A0/" target="_blank" rel="noopener">https://www.chensheng.group/2019/12/18/113-vue-cli4.0%E5%AD%A6%E4%B9%A0/</a></p>
<h2 id="前提条件"><a href="#前提条件" class="headerlink" title="前提条件"></a>前提条件</h2><h3 id="安装node-js"><a href="#安装node-js" class="headerlink" title="安装node.js"></a>安装node.js</h3><p>下载地址：<a href="https://nodejs.org/en/download/" target="_blank" rel="noopener">https://nodejs.org/en/download/</a></p>
<p>(npm会在安装node.js时默认安装好)</p>
<p>查看node.js版本</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">node -v</span><br></pre></td></tr></table></figure>

<p>查看npm版本</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm -v</span><br></pre></td></tr></table></figure>

<h3 id="安装cnpm-淘宝镜像"><a href="#安装cnpm-淘宝镜像" class="headerlink" title="安装cnpm(淘宝镜像)"></a>安装cnpm(淘宝镜像)</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install -g cnpm --registry=https://registry.npm.taobao.org</span><br></pre></td></tr></table></figure>

<p>( npm install 可简写为 npm i )</p>
<p>将npm改成使用cnpm安装模块</p>
<h3 id="安装webpack"><a href="#安装webpack" class="headerlink" title="安装webpack"></a>安装webpack</h3><p>安装方法：打开命令行工具，输入命令行：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install webpack -g</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install  webpack-cli -g</span><br></pre></td></tr></table></figure>

<p>安装成功后输入<code>webpack -v</code>,如果出现相应的版本号，则说明安装成功。</p>
<h3 id="安装vue-cli"><a href="#安装vue-cli" class="headerlink" title="安装vue-cli"></a>安装vue-cli</h3><p><strong>全局安装</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install -g @vue/cli</span><br></pre></td></tr></table></figure>

<p><strong>关于旧版本</strong></p>
<p>Vue CLI 的包名称由 <code>vue-cli</code> 改成了 <code>@vue/cli</code>。 如果你已经全局安装了旧版本的 <code>vue-cli</code> (1.x 或 2.x)，你需要先通过 <code>npm uninstall vue-cli -g</code> 或 <code>yarn global remove vue-cli</code> 卸载它。</p>
<p><strong>拉取旧版本</strong></p>
<p>Vue CLI &gt;= 3 和旧版使用了相同的 <code>vue</code> 命令，所以 Vue CLI 2 (<code>vue-cli</code>) 被覆盖了。如果你仍然需要使用旧版本的 <code>vue init</code> 功能，你可以全局安装一个桥接工具：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">npm install -g @vue/cli-init</span><br><span class="line"><span class="comment"># `vue init` 的运行效果将会跟 `vue-cli@2.x` 相同</span></span><br><span class="line">vue init webpack my-project</span><br></pre></td></tr></table></figure>

<p><strong>查看vue-cli版本</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">vue -V</span><br><span class="line">@vue/cli 4.0.5</span><br></pre></td></tr></table></figure>

<a id="more"></a>

<h2 id="vue-cli2搭建项目"><a href="#vue-cli2搭建项目" class="headerlink" title="vue-cli2搭建项目"></a>vue-cli2搭建项目</h2><h3 id="项目安装"><a href="#项目安装" class="headerlink" title="项目安装"></a>项目安装</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vue init webpack my-project（my-project为项目名,不支持大写字母）</span><br></pre></td></tr></table></figure>

<p><img src="https://gitee.com/kechenhh/tmp/raw/master/img/20201103110637.png" alt=""></p>
<p><strong>Project name 项目名</strong></p>
<p><strong>Vue build 选择第一个（运行加编译）</strong></p>
<p><strong>vue-router  选择 n  （vue的路由）</strong> </p>
<p><strong>ESLint  选择 n （代码检测工具，新手建议关闭）</strong> </p>
<p><strong>unit tests  选择 n  （单元测试工具）</strong> </p>
<p><strong>e2e tests  选择n （端到端测试）</strong></p>
<p><strong>模块安装工具 选择npm</strong></p>
<p><strong>可能的报错</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Sorry, name can no longer contain capital letters</span><br></pre></td></tr></table></figure>

<p>原因：项目名不支持大写</p>
<h3 id="项目运行"><a href="#项目运行" class="headerlink" title="项目运行"></a>项目运行</h3><p>进入项目 根目录下，再运行</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> my-project</span><br><span class="line">npm run dev</span><br></pre></td></tr></table></figure>

<p>运行其他人的项目</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">安装依赖</span></span><br><span class="line">npm install</span><br><span class="line"><span class="meta">#</span><span class="bash">运行</span></span><br><span class="line">npm run dev</span><br></pre></td></tr></table></figure>



<h3 id="项目结构"><a href="#项目结构" class="headerlink" title="项目结构"></a>项目结构</h3><p>结构详解</p>
<p><a href="https://my.oschina.net/liuyuantao/blog/883251" target="_blank" rel="noopener">https://my.oschina.net/liuyuantao/blog/883251</a></p>
<p><img src="https://gitee.com/kechenhh/tmp/raw/master/img/20201103110915.png" alt=""></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">.</span><br><span class="line">|-- build                            &#x2F;&#x2F; 项目构建(webpack)相关代码</span><br><span class="line">|   |-- build.js                     &#x2F;&#x2F; 生产环境构建代码</span><br><span class="line">|   |-- check-version.js             &#x2F;&#x2F; 检查node、npm等版本</span><br><span class="line">|   |-- dev-client.js                &#x2F;&#x2F; 热重载相关</span><br><span class="line">|   |-- dev-server.js                &#x2F;&#x2F; 构建本地服务器</span><br><span class="line">|   |-- utils.js                     &#x2F;&#x2F; 构建工具相关</span><br><span class="line">|   |-- webpack.base.conf.js         &#x2F;&#x2F; webpack基础配置</span><br><span class="line">|   |-- webpack.dev.conf.js          &#x2F;&#x2F; webpack开发环境配置</span><br><span class="line">|   |-- webpack.prod.conf.js         &#x2F;&#x2F; webpack生产环境配置</span><br><span class="line">|-- config                           &#x2F;&#x2F; 项目开发环境配置</span><br><span class="line">|   |-- dev.env.js                   &#x2F;&#x2F; 开发环境变量</span><br><span class="line">|   |-- index.js                     &#x2F;&#x2F; 项目一些配置变量</span><br><span class="line">|   |-- prod.env.js                  &#x2F;&#x2F; 生产环境变量</span><br><span class="line">|   |-- test.env.js                  &#x2F;&#x2F; 测试环境变量</span><br><span class="line">|-- src                              &#x2F;&#x2F; 源码目录</span><br><span class="line">|   |-- components                     &#x2F;&#x2F; vue公共组件</span><br><span class="line">|   |-- store                          &#x2F;&#x2F; vuex的状态管理</span><br><span class="line">|   |-- App.vue                        &#x2F;&#x2F; 页面入口文件</span><br><span class="line">|   |-- main.js                        &#x2F;&#x2F; 程序入口文件，加载各种公共组件</span><br><span class="line">|-- static                           &#x2F;&#x2F; 静态文件，比如一些图片，json数据等</span><br><span class="line">|   |-- data                           &#x2F;&#x2F; 群聊分析得到的数据用于数据可视化</span><br><span class="line">|-- .babelrc                         &#x2F;&#x2F; ES6语法编译配置</span><br><span class="line">|-- .editorconfig                    &#x2F;&#x2F; 定义代码格式</span><br><span class="line">|-- .gitignore                       &#x2F;&#x2F; git上传需要忽略的文件格式</span><br><span class="line">|-- README.md                        &#x2F;&#x2F; 项目说明</span><br><span class="line">|-- favicon.ico </span><br><span class="line">|-- index.html                       &#x2F;&#x2F; 入口页面</span><br><span class="line">|-- package.json                     &#x2F;&#x2F; 项目基本信息</span><br></pre></td></tr></table></figure>



<h2 id="vue-cli3-0-4-0搭建项目"><a href="#vue-cli3-0-4-0搭建项目" class="headerlink" title="vue-cli3.0/4.0搭建项目"></a>vue-cli3.0/4.0搭建项目</h2><p>3.0/4.0 的安装过程相同，只是目录结构有变化</p>
<h3 id="项目安装-1"><a href="#项目安装-1" class="headerlink" title="项目安装"></a>项目安装</h3><h4 id="1-命令行安装"><a href="#1-命令行安装" class="headerlink" title="1.命令行安装"></a>1.命令行安装</h4><p>安装命令</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vue create my-project</span><br></pre></td></tr></table></figure>

<p>选择配置   默认（default）或者自定义(Manually select features)，my是我自己保存的配置。</p>
<p><img src="https://gitee.com/kechenhh/tmp/raw/master/img/20201103133004.png" alt=""></p>
<p>选择自定义配置</p>
<p>选择功能</p>
<p><img src="https://gitee.com/kechenhh/tmp/raw/master/img/20201103134157.png" alt=""></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">按空格键选择你需要的功能，选完后按回车</span><br><span class="line"></span><br><span class="line">babel：javascript转译器，将最新版的js语法（es6、es7）转换为现阶段浏览器可以兼容的js代码</span><br><span class="line">typescript：使用 TypeScript 书写源码</span><br><span class="line">PWA：渐进式WEB应用</span><br><span class="line">Router：使用vue-router</span><br><span class="line">Vuex：使用vuex</span><br><span class="line">CSS Pre-processors：css预处理器</span><br><span class="line">Linter &#x2F; Formatter：代码规范标准</span><br><span class="line">Unit Testing：单元测试</span><br><span class="line">E2E Testing：e2e测试</span><br></pre></td></tr></table></figure>

<p> Use history mode for router? —router是否使用history模式</p>
<p>history需要服务器支持   详情看这儿<a href="https://links.jianshu.com/go?to=https%3A%2F%2Frouter.vuejs.org%2Fzh%2Fguide%2Fessentials%2Fhistory-mode.html" target="_blank" rel="noopener">https://router.vuejs.org/zh/guide/essentials/history-mode.html</a><br>这里我就选no</p>
<p>Pick a CSS pre-processor  —css预处理器的选择</p>
<p>Pick a linter / formatter config —代码格式化检测选择（这里选择 ESLint + Prettier）</p>
<p> Pick additional lint features  —是否保存配置</p>
<p>Where do you prefer placing config for Babel, PostCSS, ESLint, etc.?</p>
<p>—-关于Babel, PostCSS, ESLint, etc.这些配置文件你是想放在package.json里面还是单独放在外面</p>
<p>（编辑器一般默认会在项目根目录下寻找配置文件，这里我就直接回车选择In dedicated config files）</p>
<p>Save this as a preset for future projects?</p>
<p>— 是否保存为未来项目的预配置吗？</p>
<h4 id="2-图形化安装"><a href="#2-图形化安装" class="headerlink" title="2.图形化安装"></a>2.图形化安装</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">执行npm命令</span><br><span class="line">vue ui</span><br><span class="line">访问 http://localhost:8000 你就可以创建，管理，导入项目</span><br></pre></td></tr></table></figure>

<h3 id="项目运行-1"><a href="#项目运行-1" class="headerlink" title="项目运行"></a>项目运行</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm run serve</span><br></pre></td></tr></table></figure>

<p>由于vue4.0取消了以前的那些配置文件,所以我们需要在根目录自己创建一个<code>vue.config.js</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> path = <span class="built_in">require</span>(<span class="string">'path'</span>);</span><br><span class="line"></span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  publicPath: <span class="string">'./'</span>,</span><br><span class="line">  <span class="comment">// 输出文件目录,默认就是dist</span></span><br><span class="line">  outputDir: process.env.NODE_ENV === <span class="string">"test"</span> ? <span class="string">'distTest'</span> : <span class="string">'distPro'</span>,</span><br><span class="line">  <span class="comment">// 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录。</span></span><br><span class="line">  assetsDir: <span class="string">'static'</span>,</span><br><span class="line">  <span class="comment">// 生产环境是否生成 sourceMap 文件</span></span><br><span class="line">  productionSourceMap: <span class="literal">false</span>,</span><br><span class="line">  <span class="comment">// 配置es-link true,'error'</span></span><br><span class="line">  lintOnSave: <span class="literal">true</span>,</span><br><span class="line">  css: &#123;  <span class="comment">// 一次配置，全局使用，这个scss 因为每个文件都要引入</span></span><br><span class="line">    loaderOptions: &#123;</span><br><span class="line">      sass: &#123;</span><br><span class="line">        prependData: <span class="string">`@import "./src/assets/css/index.scss";`</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">// webpack-dev-server 相关配置</span></span><br><span class="line">  devServer: &#123;</span><br><span class="line">    <span class="comment">// 可以通过设置让浏览器 overlay 同时显示警告和错误：</span></span><br><span class="line">    overlay: &#123;</span><br><span class="line">      warnings: <span class="literal">false</span>,</span><br><span class="line">      errors: <span class="literal">false</span></span><br><span class="line">    &#125;,</span><br><span class="line">    open: <span class="literal">false</span>,</span><br><span class="line">    host: <span class="string">'localhost'</span>,</span><br><span class="line">    port: <span class="number">8080</span>,</span><br><span class="line">    https: <span class="literal">false</span>,</span><br><span class="line">    proxy: &#123;</span><br><span class="line">      <span class="string">'/mgr'</span>: &#123;</span><br><span class="line">        target: <span class="string">'https://api.douban.com'</span>,</span><br><span class="line">        ws: <span class="literal">true</span>,</span><br><span class="line">        changeOrigin: <span class="literal">true</span>,</span><br><span class="line">        pathRewrite:&#123;</span><br><span class="line">          <span class="string">'^/mgr'</span>: <span class="string">''</span></span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  configureWebpack:&#123;  <span class="comment">// 覆盖webpack默认配置的都在这里</span></span><br><span class="line">    resolve:&#123;   <span class="comment">// 配置解析别名</span></span><br><span class="line">      alias:&#123;</span><br><span class="line">        <span class="string">'@'</span>: path.resolve(__dirname, <span class="string">'./src'</span>)</span><br><span class="line">      &#125; </span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Vue/" rel="tag"># Vue</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/vue%E9%A1%B9%E7%9B%AE%E6%89%93%E5%8C%85%E5%90%8E%E6%89%93%E5%BC%80%E7%A9%BA%E7%99%BD%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95.html" rel="prev" title="vue项目打包后打开空白解决办法">
      <i class="fa fa-chevron-left"></i> vue项目打包后打开空白解决办法
    </a></div>
      <div class="post-nav-item">
    <a href="/%E7%A6%81%E6%AD%A2%E8%B0%B7%E6%AD%8C%E6%B5%8F%E8%A7%88%E5%99%A8%E5%8D%87%E7%BA%A7.html" rel="next" title="禁止谷歌浏览器升级">
      禁止谷歌浏览器升级 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#官方文档"><span class="nav-number">1.</span> <span class="nav-text">官方文档</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#参考"><span class="nav-number">2.</span> <span class="nav-text">参考</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#前提条件"><span class="nav-number">3.</span> <span class="nav-text">前提条件</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#安装node-js"><span class="nav-number">3.1.</span> <span class="nav-text">安装node.js</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#安装cnpm-淘宝镜像"><span class="nav-number">3.2.</span> <span class="nav-text">安装cnpm(淘宝镜像)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#安装webpack"><span class="nav-number">3.3.</span> <span class="nav-text">安装webpack</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#安装vue-cli"><span class="nav-number">3.4.</span> <span class="nav-text">安装vue-cli</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#vue-cli2搭建项目"><span class="nav-number">4.</span> <span class="nav-text">vue-cli2搭建项目</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#项目安装"><span class="nav-number">4.1.</span> <span class="nav-text">项目安装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#项目运行"><span class="nav-number">4.2.</span> <span class="nav-text">项目运行</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#项目结构"><span class="nav-number">4.3.</span> <span class="nav-text">项目结构</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#vue-cli3-0-4-0搭建项目"><span class="nav-number">5.</span> <span class="nav-text">vue-cli3.0&#x2F;4.0搭建项目</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#项目安装-1"><span class="nav-number">5.1.</span> <span class="nav-text">项目安装</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-命令行安装"><span class="nav-number">5.1.1.</span> <span class="nav-text">1.命令行安装</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-图形化安装"><span class="nav-number">5.1.2.</span> <span class="nav-text">2.图形化安装</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#项目运行-1"><span class="nav-number">5.2.</span> <span class="nav-text">项目运行</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="kechenhh"
      src="/images/avatar.gif">
  <p class="site-author-name" itemprop="name">kechenhh</p>
  <div class="site-description" itemprop="description">学习笔记</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">19</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">10</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">12</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/kechenhh" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;kechenhh" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">kechenhh</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v4.2.1
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> v7.7.0
  </div>

        








      </div>
    </footer>
  </div>

  
  
  <script color='0,0,255' opacity='0.5' zIndex='-1' count='99' src="/lib/canvas-nest/canvas-nest.min.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  

</body>
</html>
